package com.pqmvc{
	import core.mgr.LayerMgr;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.utils.Dictionary;
	public class PQController implements IControl{
		private var md:PQMediator;
		private var _inited:Boolean=false;
		private var delayList:Array=[];
		/**等待处理的事件列表，inited为false时所有事件都存储在这里，为true后遍历触发**/
		protected var eventList:Array=[];
		public function PQController()
		{
		}
		public function set Mediator(m:PQMediator):void{
			if(md!=null)throw new Error("Mediator已赋值");
			md=m;
		}
		public function get inited():Boolean	{
			return _inited;
		}
		public function set inited(value:Boolean):void{
			_inited = value;
			if(value){
				while(delayList.length>0){
					execute(delayList[1],delayList[0])
					delayList.shift();
				}
			}
		}
		/**发送指令到command处理**/
		public function command(name:String,param:Object=null,type:String=null):void{
			md.command(name,param,type);
		}
		/**监听消息**/
		protected function addListen(event:String,callBack:Function):void{
			md.addListen(event,callBack);
		}
		/**广播**/
		protected function call(name:String,param:Object=null):void{
			md.call(name,param);
		}
		/**删除监听**/
		protected function removeListen(name:String,func:Function):void{
			md.removeListen(name,func);
		}
		/**
		 *获取共享数据 
		 * @param key 钥匙
		 * @param args 参数
		 * @return 
		 * 
		 */		
		public function getData(key:String,...args):Object{
			return md.getData(key,args);
		}
		public function shareData(key:String,data:Function):void{
			md.shareData(key,data);
		}
		/**如果界面还没初始化则延迟到初始化后再执行**/
		protected function delay(name:String,param:Object=null):void{
			delayList.push([name,param]);
		}
		/**调用UI逻辑**/
		public function control(name:String,data:Object=null,type:String=null):void{
			md.control(name,data,type);
		}
		public function execute(param:Object=null, type:String=null):void
		{
			// TODO Auto-generated method stub
		}
	}
}